package com.lzc.zhxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzc.zhxy.mapper.TbClazzMapper;
import com.lzc.zhxy.pojo.TbClazz;
import com.lzc.zhxy.service.TbClazzService;
import org.springframework.util.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* @author 82389
* @description 针对表【tb_clazz】的数据库操作Service实现
* @createDate 2022-04-16 18:00:43
*/
@Service("tbClazzService")
@Transactional
public class TbClazzServiceImpl extends ServiceImpl<TbClazzMapper, TbClazz>implements TbClazzService {

    /**
     * 查询班级信息,分页带条件
     * @param page
     * @param clazz
     * @return
     */
    @Override
    public Page<TbClazz> getClazzsByOpr(Page<TbClazz> page, TbClazz clazz) {
        QueryWrapper<TbClazz> queryWrapper = new QueryWrapper<>();
        if (clazz!=null){
            //年级名称条件
            String gradeName = clazz.getGradeName();
            if (!StringUtils.isEmpty(gradeName)){
                queryWrapper.eq("grade_name",gradeName);
            }
            //班级名称条件
            String clazzName = clazz.getName();
            if (!StringUtils.isEmpty(clazzName)){
                queryWrapper.eq("name",clazzName);
            }
            queryWrapper.orderByDesc("id");
            queryWrapper.orderByAsc("name");
        }
        Page<TbClazz> selectPage = baseMapper.selectPage(page, queryWrapper);
        return selectPage;
    }
}
